import ContainerPage from "@/src/components/layouts/container-page"; import { StatusBadge } from "@/src/components/layouts/status-badge"; import { AutomationButton } from "@/src/features/automations/components/AutomationButton"; import { SlackConnectionCard } from "@/src/features/slack/components/SlackConnectionCard"; import { ChannelSelector, type SlackChannel, } from "@/src/features/slack/components/ChannelSelector"; import { SlackTestMessageButton } from "@/src/features/slack/components/SlackTestMessageButton"; import { api } from "@/src/utils/api"; import { useRouter } from "next/router"; import { useState, useEffect } from "react"; import { Badge } from "@/src/components/ui/badge"; import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/src/components/ui/card"; export default function SlackIntegrationSettings() { const router = useRouter(); const projectId = router.query.projectId as string; // Handle popup OAuth completion useEffect(() => { // Check if this page is opened in a popup window const isPopup = window.opener && window.opener !== window; if (isPopup) { // Check for OAuth completion parameters const urlParams = new URLSearchParams(window.location.search); const success = urlParams.get("success"); const error = urlParams.get("error"); const teamName = urlParams.get("team_name"); if (success === "true") { // Send success message to parent window window.opener.postMessage( { type: "slack-oauth-success", teamName: teamName || "your Slack workspace", }, window.location.origin, ); // Close popup window.close(); } else if (error) { // Send error message to parent window window.opener.postMessage( { type: "slack-oauth-error", error: error, }, window.location.origin, ); // Close popup window.close(); } } }, [router.query]); const { data: integrationStatus, isInitialLoading } = api.slack.getIntegrationStatus.useQuery( { projectId }, { enabled: !!projectId }, ); const status = isInitialLoading ? undefined : integrationStatus?.isConnected ? "active" : "inactive"; const [selectedChannel, setSelectedChannel] = useState( null, ); // Check user permissions const hasAccess = useHasProjectAccess({ projectId, scope: "automations:CUD", }); return ( {status && }, actionButtonsRight: , }} >
{/* Connection Configuration */} {/* Test Channel Section - Only show when connected */} {integrationStatus?.isConnected && ( Test Integration Test your Slack integration by sending a message to a channel.

Select Test Channel

{selectedChannel && (

Channel Information

Channel Name

#{selectedChannel.name}

Channel Type

{selectedChannel.isPrivate ? "Private" : "Public"}

Channel ID

{selectedChannel.id}

)} {!selectedChannel && (
Select a channel above to view its details and test message delivery.
)}
)}
); }